package cn.easybuy.web.backend;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.HttpConstraint;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebEndpoint;

import cn.easybuy.entity.News;
import cn.easybuy.service.news.NewsService;
import cn.easybuy.service.news.NewsServiceImpl;
import cn.easybuy.utils.NewsPage;


public class NewsListServlet extends HttpServlet {

	public NewsListServlet() {
		super();
	}


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		NewsService ns = new NewsServiceImpl();
		NewsPage page = new NewsPage();
		String pageNo = request.getParameter("pageNo");
		if(pageNo==null){
			pageNo ="1";
		}
		page.setPageNo(Integer.parseInt(pageNo));
		int pageSize = 1;
		page.setPageSize(pageSize);
		page.setDataNum(ns.getCount());
		page.setList(ns.getPageList(Integer.parseInt(pageNo), pageSize));
		request.setAttribute("page", page);
		request.getRequestDispatcher("NewsList.jsp").forward(request, response);
	}

}
